package org.groupg.practice.commons;

import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.sql.SparkSession;
import org.groupg.practice.calcConfig.model.TableTask;

import java.util.Properties;

public class CommonsService {

    SparkSession spark;

    public void execute(TableTask tableTask) {
        spark = SparkSession
                .builder()
                .appName(tableTask.getTableInfo().getTableName() + "处理中~")
                .getOrCreate();

        Properties properties = new Properties();
        properties.put("user", "mysqldemo");
        properties.put("password", "mysqldemo123");
        properties.put("fetchsize", 50);

        JavaRDD tableRows = spark.read().jdbc("jdbc:mysql://localhost:3306/mysqldemo", "FC_LOAN", properties).javaRDD();

        tableRows.foreach(System.out::println);


        spark.cloneSession();
    }
}
